﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;

namespace Royaumes_Libres
{
    public partial class adminbuilding : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.InitPage();
        }

        protected void InitPage()
        {
            cBuildingsAdmin[] buildings = cBuildingsAdmin.GetBuildings();
            ucBuildingAdmin ctlBuilding;

            this.btnSave.Click += new EventHandler(btnSave_Click);

            foreach (cBuildingsAdmin building in buildings)
            {
                ctlBuilding = building.GetControl(Page);
                this.divBuildings.Controls.Add(ctlBuilding);
            }
        }

        void btnSave_Click(object sender, EventArgs e)
        {
            foreach (Control uc in this.divBuildings.Controls)
            { 
                if (uc is ucBuildingAdmin) { ((ucBuildingAdmin)uc).Save(); } 
            }
            Response.Redirect("adminbuilding.aspx");
        }
    }
}